<?php

declare(strict_types=1);

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 *  通话评价
 */
class CallComment extends Model
{
    protected $table = 'call_comment';
    protected $fillable = ['flag'];

    const LEVEL = [
        1 => '满意',
        2 => '一般',
        3 => '不满意'
    ];

    const TAG = [
        1 => ['tag_id' => 1, 'text' => '有话题'],
        ['tag_id' => 2, 'text' => '善解人意'],
        ['tag_id' => 3, 'text' => '整体不错'],
        ['tag_id' => 4, 'text' => '活泼热情'],
        ['tag_id' => 5, 'text' => '人美声甜'],
    ];

    static function getTagsById($ids = [])
    {
        $tags = [];
        foreach ($ids as $id) $tags[] = self::TAG[$id]['text'];
        return $tags;
    }

    static function getCommentsByChannel($channelIds = [])
    {
        $items = self::whereIn('channel_id', $channelIds)->get()->toArray();
        $comments = [];
        foreach ($items as $item) $comments[$item['channel_id']][] = self::LEVEL[$item['level']];
        return $comments;
    }

    public function userProfile()
    {
        return $this->belongsTo(UserProfile::class, 'user_id', 'user_id');
    }
}
